package com.nota.flink.cdc.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author 胡超雄
 * @date 2024/01/15 10:23
 * @desc 线程池配置
 */
@Configuration
public class ExecutorPoolConfig {

    /**
     * 发送钉钉专用
     *
     * @return
     */
    @Bean(name = "statisticDingMsg")
    public Executor statisticDingMsgExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
        executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 2);
        executor.setQueueCapacity(100);
        executor.setKeepAliveSeconds(100);
        executor.setThreadNamePrefix("statistic-ding-msg");
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(10);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
}
